#include "ParticleSwitch.h"

#include "ParticleContext.h"
#include "DescriptorParticle.h"

#//include "StreamBinary.h"

using namespace ParticleEngine; 

const DescriptorParticle ParticleSwitch::Descriptor
(
	"Switch", 
	[](ParticleContext& NewContext) { return new ParticleSwitch(NewContext); }
); 

ParticleSwitch::ParticleSwitch(ParticleContext& NewContext) :
ParticleBase(NewContext, &ParticleSwitch::Descriptor),
PropertyAdhesions(0.15f),
Heat(1.0f),
Electricity(0.0f),
{
	this->Adhesions = dynamic_cast<PropertyAdhesions*>(this);
	this->Adhesions->ParticleCast = dynamic_cast<ParticleBase*>(this);
}
ParticleSwitch::~ParticleSwitch()
{
}

void ParticleSwitch::Sole()//einzelne aktualisierzung
{
	this->SoleStandard();

	this->Heat.Sole();
	if (Switch.Status) this->Electricity.Sole();

	this->Signal0.Sole();
	this->Signal1.Sole();

	this->Switch.Sole(Signal0, Signal1);

}
void ParticleSwitch::InteractionIndividual(ParticleBase*const Other, Vec<2, float>& Space, const float& DistanceSquared)
{
	this->InteractionKinetics(Other, Space, DistanceSquared);

	this->Heat.Interaction(Other->HasHeat());
	if (Switch.Status == true) this->Electricity.Interaction(Other->HasElectricity());

	this->Signal0.Interaction(Other->HasSignal0());
	this->Signal1.Interaction(Other->HasSignal1());
}
ColorRGBA<unsigned char> ParticleSwitch::GetColor()
{
	if (Switch.Status == true)
		return ColorRGBA<unsigned char> (50, 255, 50, 255);
	else
		return ColorRGBA<unsigned char> (255, 50, 50, 255);
}

void ParticleSwitch::SaveIndividual(std::ofstream& Strm)
{
	Heat.Save(Strm);
	Signal0.Save(Strm);
	Signal1.Save(Strm);
}
void ParticleSwitch::LoadIndividual(std::ifstream& Strm)
{
	Heat.Load(Strm);
	Signal0.Load(Strm);
	Signal1.Load(Strm);
}


